package com.example.yyy




import android.content.DialogInterface
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.text.TextUtils
import android.view.Gravity

import android.widget.ImageView
import androidx.appcompat.app.AlertDialog


import kotlinx.android.synthetic.main.activity_image_text.*
import org.jetbrains.anko.AlertBuilder
import org.jetbrains.anko.alert
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.toast

class ImageTextActivity : AppCompatActivity() {
    private var bPause =true
    private var bCount =0
    private var create: AlertDialog? = null
    private var alert: AlertBuilder<android.app.AlertDialog>?=null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_image_text)
        tv_it_text.text = "中央气象台 22:36发布28°晴64 良高温预警 西南风 2级 湿度 27% 气压 1002hPa 不限行 现在的温度比较舒适~"
        tv_it_text.textSize = 17f
        tv_it_text.setTextColor(Color.BLACK)
        tv_it_text.setBackgroundColor(Color.WHITE)
        //内部布局设置
        tv_it_text.gravity = Gravity.LEFT or  Gravity.CENTER_VERTICAL
        //仅一行
        tv_it_text.isSingleLine = true
        //展示方式轮播
        tv_it_text.ellipsize = TextUtils.TruncateAt.MARQUEE
        //轮播支持
        tv_it_text.isSelected = true
        //轮播暂停
        tv_it_text.setOnClickListener {
            bPause = !bPause
            tv_it_text.isFocusable = bPause
            tv_it_text.isFocusableInTouchMode = bPause
            toast("")
        }
        tv_it_text.setOnLongClickListener{

            true
        }
        iv_it_image.setImageResource(R.drawable.tp)
        iv_it_image.setOnClickListener{
            bCount++
            iv_it_image.scaleType = when(bCount%7){
                0 -> ImageView.ScaleType.FIT_XY//拉伸填充
                1 -> ImageView.ScaleType.FIT_START//拉伸位于视图上部
                2 -> ImageView.ScaleType.FIT_CENTER//拉伸位于视图中间
                3 -> ImageView.ScaleType.FIT_END//拉伸位于视图下部
                4 -> ImageView.ScaleType.CENTER//原图 位中
                5 -> ImageView.ScaleType.CENTER_CROP//拉伸填充位中
                else -> ImageView.ScaleType.CENTER_INSIDE//使中只压不拉
            }
//            create?.show()
            alert?.show()
        }
        alertDialog()
        alertDialogAnko()

    }
    //anko对话框
    private fun alertDialogAnko() {
       alert = alert("确认跳转", "尊敬的用户") {
            positiveButton("确认") { startActivity<ViewActivity>() }
            negativeButton("取消") { toast("5") }
        }
    }
    //对话框
    private fun alertDialog() {
        var builder = AlertDialog.Builder(this)
        builder.setTitle("尊敬的用户")
        builder.setMessage("请确认删除")
        builder.setPositiveButton("确认删除",{ dialogInterface: DialogInterface, i: Int -> toast("1")})
        builder.setNegativeButton("取消",{ dialogInterface: DialogInterface, i: Int -> toast("2")})
        create = builder.create()
    }
}








